//-----------------------------------------------------------------------------
//	File: mgui_menu.c
//	Author: xialing
//		menu of mgui
//-----------------------------------------------------------------------------

#ifndef __MGUI_MENU_H__
#define __MGUI_MENU_H__

#include <string.h>
#include "mgui_config.h"
#include "mgui_font.h"
#include "mgui_2d.h"

// struct type declaration
typedef struct MguiFont_Type MguiFont_TypeDef;
typedef struct MenuMesg_Type MenuMesg_TypeDef;
typedef struct MenuList_Type MenuList_TypeDef;
typedef struct MenuItem_Type MenuItem_TypeDef;
typedef struct MenuConf_Type MenuConf_TypeDef;
typedef struct Menu_Type Menu_TypeDef;

// menu message type define
typedef struct MenuMesg_Type {
	uint8_t id;
	uint8_t opt;
} MenuMesg_TypeDef;

// menu list type define
typedef struct MenuList_Type {
	char *name;
	uint8_t num;
	MenuList_TypeDef *parent;
	MenuItem_TypeDef *array;
} MenuList_TypeDef;

// menu item type define
typedef struct MenuItem_Type {
	char *name;
	uint8_t id;
	MenuList_TypeDef *child;
} MenuItem_TypeDef;

// menu configuration type define
typedef struct MenuConf_Type {
	uint16_t menu_x1; // menu windows start x position
	uint16_t menu_y1; // menu windows start y position
	uint16_t menu_x2; // menu windows end x position
	uint16_t menu_y2; // menu windows end y position
	uint16_t item_x1; // item windows start x position
	uint16_t item_y1; // item windows start y position
	uint16_t item_x2; // item windows end x position
	uint16_t item_y2; // item windows end y position
	uint8_t gapx; // the gap x between rect and menu
	uint8_t gapy; // the gap y between rect and menu
	MguiFont_TypeDef *font;
} MenuConf_TypeDef;

// menu type define
typedef struct Menu_Type {
	uint8_t sel; // 0=menu_win_sel 1=item_win_sel
	uint8_t top;
	uint8_t top_l; // top last
	uint8_t item;
	uint8_t item_l; // item last
	uint8_t row; // number of rows
	uint8_t col; // number of columns
	MenuList_TypeDef *list;
	MenuConf_TypeDef *conf;
	void (*func)(MenuMesg_TypeDef);
} Menu_TypeDef;

enum FUNC_OPT {
	FUNC_DISP = 0,
	FUNC_ENTER,
	FUNC_UP,
	FUNC_DOWN,
};

//-----------------------------------------------------------------------------
//	mgui_menu_init - init menu
//		@m: menu
//-----------------------------------------------------------------------------
void mgui_menu_init(Menu_TypeDef *m, void (*f)(MenuMesg_TypeDef));

//-----------------------------------------------------------------------------
//	menu_disp - display the menu
//-----------------------------------------------------------------------------
void mgui_menu_disp(void);

//-----------------------------------------------------------------------------
//	mgui_menu_enter - enter the subordinate menu or execute a function
//-----------------------------------------------------------------------------
void mgui_menu_enter(void);

//-----------------------------------------------------------------------------
//	mgui_menu_up - go to the up item of menu
//-----------------------------------------------------------------------------
void mgui_menu_up(void);

//-----------------------------------------------------------------------------
//	mgui_menu_down - go to the down item of menu
//-----------------------------------------------------------------------------
void mgui_menu_down(void);

//-----------------------------------------------------------------------------
//	mgui_menu_back - back to the parent menu
//-----------------------------------------------------------------------------
void mgui_menu_back(void);

//-----------------------------------------------------------------------------
//	mgui_menu_back - back to the parent menu
//		@sw: 0=menu, 1=item, 2=inv
//-----------------------------------------------------------------------------
void mgui_menu_sel(uint8_t sw);

#endif
